import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { viteMockServe } from 'vite-plugin-mock'

// https://vitejs.dev/config/
export default defineConfig((config) => {
  const { command } = config
  console.log('command:', command)
  return {
    plugins: [vue(),
    viteMockServe({
      mockPath: '/src/mock',
      //只有在开发环境开启mock 服务
      localEnabled: true,
    })

    ],
    //开发服务器(本地)配置
    server: {
      //设置端口
      port: 8095,
      open: '/docs/index.html',
      hmr: {
        overlay: false
      },
      //代理：解决联调跨域
      proxy: {
        '/api': {
          target: '',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, '')
        }
      }
    },
    //生产服务器(线上)配置
    build: {

    },
    //预览服务器(测试)配置
    preview: {

    }
  }
})
